#include "pagewidget.h"
#include "ui_pagewidget.h"
#include "globaldef.h"

QPageWidget::QPageWidget(QWidget *parent) :
    IPageFrame(parent),
    ui(new Ui::PageWidget)
{
    ui->setupUi(this);
    ui->widgetTitle->setParentWidget(this);
    this->setWindowFlags(Qt::FramelessWindowHint);

//    GlobalSpace::LoadQss(GlobalSpace::BLACK_QSS_FILE_PATH);

    syetemTray = new SystemTray(this);
    connect(syetemTray->getShowWidget(), SIGNAL(triggered(bool)), this, SLOT(showNormal()));
    connect(syetemTray->getMinWidget(), SIGNAL(triggered(bool)), this, SLOT(showMinimized()));
    connect(ui->widgetTree, SIGNAL(sendShowIndex(int)), ui->stackedWidget, SLOT(setCurrentIndex(int)));

//#ifdef QT_DEBUG
//    auto label = new QLabel("");
//    label->setStyleSheet("QLabel{background-color:rgb(200,101,102);}");
//    addPage(label, "test");
//    receiveShow(0);
//#endif

}

QPageWidget::~QPageWidget()
{
    delete ui;
}

void QPageWidget::addPage(QWidget *page, const QString &name)
{
    ui->widgetTree->addPage(name);
    ui->stackedWidget->addWidget(page);
}

void QPageWidget::showPage(int index)
{
    receiveShow(index);
}

void QPageWidget::receiveShow(int index)
{
    int count = ui->stackedWidget->count();
    if (index >= 0 && index < count)
    {
        ui->stackedWidget->setCurrentIndex(index);
    }
}

#if (QT_VERSION < QT_VERSION_CHECK(5, 0, 0))
    Q_EXPORT_PLUGIN2(QPageWidget, QPageWidget);
#endif
